#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_ttf.h>

int main()
{
        
        
	SDL_Color couleurblanche = {255, 255, 255};
	
        int i=1;
	int j,x=-1,y=-1;
	int continuer=1;
	
	SDL_Event event;
	

	SDL_Surface *ecran = NULL, *T_fond[5], 
	
	 
	
	
	SDL_Rect posiotnFond;
	
	

	
      

	T_fond[0].x = 800;
	T_fond[0].y = 415;
	
	T_fond[1].x = 800;
	T_fond[1].y = 310;

	T_fond[2].x = 800;
	T_fond[2].y = 210;

	T_fond[3].x = 800;
	T_fond[3].y = 0;

	T_fond[4].x = 800 ;
	T_fond[4].y = 105;

	SDL_Rect posiotnFond1;

	posiotnFond1.x = 0;
	posiotnFond1.y = 0;

	SDL_Init(SDL_INIT_VIDEO);
	if (SDL_Init(SDL_INIT_VIDEO)== -1)
	{
		fprintf(stderr, "erreure d'initialisation:%s\n",SDL_GetError() );
		exit(EXIT_FAILURE);
	}
	else
	{
		ecran=SDL_SetVideoMode(870,600,32, SDL_HWSURFACE | SDL_DOUBLEBUF);
		SDL_WM_SetCaption("looupinaft",NULL);
		
		T_fond[0]= SDL_LoadBMP("1.bmp");
		T_fond[1]= SDL_LoadBMP("2.bmp");
		T_fond[2]= SDL_LoadBMP("3.bmp");
		T_fond[3]= SDL_LoadBMP("4.bmp");
		
		SDL_BlitSurface(T_fond[0], NULL,ecran,&posiotnFond);
		
		

		barre = SDL_CreateRGBSurface(SDL_HWSURFACE,70,600,32,0,0,0,0);
		

		
		
		SDL_Flip(ecran);
		while(continuer)
		{
			
			SDL_WaitEvent(&event);
			switch(event.type)
			{
			case SDL_QUIT:
				continuer = 0;
			break;

			case SDL_KEYDOWN:
						
				switch(event.key.keysym.sym)
				{
					case SDLK_DOWN:
						i++;
					break;

					case SDLK_UP:
						i--;
					break;

					case SDLK_ESCAPE:
						continuer=0;
					break;
				}
			break;

			case SDL_MOUSEBUTTONDOWN:
				x=event.button.x;
				y=event.button.y;
				if (x>=800)
				{
					if (y<90)
					{
						i=1;
					}
					else if ((y>T_fond[1].y) && (y<T_fond[1].y+90))
					{
						i=2;
					}
					else if ((y>T_fond[2].y) && (y<T_fond[2].y+90))
					{
						i=3;
					}
					else if ((y>T_fond[3].y) && (y<T_fond[3].y+90))
					{
						i=4;
					}
					else if ((y>T_fond[4].y) && (y<T_fond[4].y+90))
					{
						i=5;
					}
				}
				
						
			break;

			}
			
			if (i<1)
			{
				i=1;
			}
			else if (i>5)
			{
				i=5;
			}
			else
			{	
				
				for (j = 0; j <= 4; ++j)
				{
					if (j+1==i)
					{
						SDL_BlitSurface(T_fond[j], NULL,ecran,&posiotnFond);
						
					}
					
				}
				
				
			}
			
		SDL_Flip(ecran);
		}	
	}

	for (j = 0; j <= 4; ++j)
		SDL_FreeSurface(T_fond[j]);
	
	SDL_Quit();
	return EXIT_SUCCESS;
}
